package com.android.memory;

import com.android.memory.R;

import android.app.Activity;
import android.content.Intent;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;



public class MainMenuActivity extends Activity implements OnClickListener {
    /** Called when the activity is first created. */
	
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, 
                                WindowManager.LayoutParams.FLAG_FULLSCREEN);
        
        setContentView(R.layout.main);
        
        //Menu buttons
        final Button startButton = (Button)findViewById(R.id.newGameButton);
  	  		  startButton.setOnClickListener(this);
  	  	final Button optionsButton = (Button)findViewById(R.id.optionsButton);
  	  		  optionsButton.setOnClickListener(this);
  	    final Button highscoreButton = (Button)findViewById(R.id.highscoreButton);
  	    	  highscoreButton.setOnClickListener(this);
  	    final Button quitButton = (Button)findViewById(R.id.quitButton);
	    	  quitButton.setOnClickListener(this);
	    	  
    }

    //On click events for buttons
	public void onClick(View v) {
		switch(v.getId()){
		case R.id.newGameButton:
			Intent gameIntent = new Intent(this, GameActivity.class);
			startActivity(gameIntent);
			break;
		case R.id.optionsButton:
			Intent optionsIntent = new Intent(this, OptionsActivity.class);
			startActivity(optionsIntent);
			break;
		case R.id.highscoreButton:
			Intent highscoreIntent = new Intent(this, HighscoreActivity.class);
			startActivity(highscoreIntent);
			break;
		case R.id.quitButton:
			finish();
		}
		
	}
	
	public void onStart() {
		super.onStart();
		//if music is on, then sets continueMusic to true
		if(OptionsActivity.musicPlayer)
			MusicManagerService.setContinueMusic(true);
	}
	
	public void onStop() {
		super.onStop();
		if(!MusicManagerService.getContinueMusic())
		{
	    	Intent backgroundmusic= new Intent(this, MusicManagerService.class);
			stopService(backgroundmusic);
		}
	}
	
	public void onPause() {
		super.onPause();
		MusicManagerService.setContinueMusic(false);
	}
	
	public void onResume() {
		super.onResume();
		if(OptionsActivity.musicPlayer) {
			MusicManagerService.setContinueMusic(true);
	    	Intent backgroundmusic= new Intent(this, MusicManagerService.class);
			startService(backgroundmusic);
		}
	}
	
	public void onDestroy() {
		super.onDestroy();
	}
}